using System.Xml.Linq;
using Engine;
using Game;
using SCIENEW.Tech;

namespace SCIENEW {
    public class TechTreeNodeInfoWidget : CanvasWidget {
        public TechNode m_node;

        public TechNode Node {
            get => m_node;
            set => m_node = value;
        }

        public TechTreeBlockIconWidget m_blockIcon;
        public LabelWidget m_titleLabel;
        public LabelWidget m_descLabel;
        public BevelledButtonWidget m_recipeButton;
        public BevelledButtonWidget m_descButton;
        public Action OnRecipeButtonClicked;
        public Action OnDescButtonClicked;

        public TechTreeNodeInfoWidget() {
            XElement node = ContentManager.Get<XElement>("Widgets/TechTreeNodeInfoWidget");
            LoadContents(this, node);
            m_blockIcon = Children.Find<TechTreeBlockIconWidget>("Icon");
            m_titleLabel = Children.Find<LabelWidget>("Title");
            m_descLabel = Children.Find<LabelWidget>("Description");
            m_recipeButton = Children.Find<BevelledButtonWidget>("RecipeButton");
            m_descButton = Children.Find<BevelledButtonWidget>("DescriptionButton");
        }

        public override void MeasureOverride(Vector2 parentAvailableSize) {
            base.MeasureOverride(parentAvailableSize);
            if (m_node != null) {
                m_blockIcon.Value = m_node.IconBlock;
                m_titleLabel.Text = m_node.DisplayName;
                m_descLabel.Text = m_node.Description;
                m_recipeButton.IsVisible = true;
                m_descButton.IsVisible = true;
            }
            else {
                m_blockIcon.Value = 0;
                m_titleLabel.Text = m_descLabel.Text = string.Empty;
                m_recipeButton.IsVisible = false;
                m_descButton.IsVisible = false;
            }
        }
    }
}